


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > PointCalculatorLoader</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.points</a>
</div>

<h1>Coverage Summary for Class: PointCalculatorLoader (nl.tudelft.jpacman.points)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">PointCalculatorLoader</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/17)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.points;
&nbsp;
&nbsp;import java.io.IOException;
&nbsp;import java.net.URL;
&nbsp;import java.net.URLClassLoader;
&nbsp;import java.util.Properties;
&nbsp;
&nbsp;/**
&nbsp; * The responsibility of this loader is to obtain the appropriate points calculator.
&nbsp; * By default the {@link DefaultPointCalculator} is returned.
&nbsp; */
<b class="nc">&nbsp;public class PointCalculatorLoader {</b>
&nbsp;
<b class="nc">&nbsp;    private static Class clazz = null;</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Load a points calculator and return it.
&nbsp;     *
&nbsp;     * @return The (dynamically loaded) points calculator.
&nbsp;     */
&nbsp;    public PointCalculator load() {
&nbsp;        try {
<b class="nc">&nbsp;            if (clazz == null) {</b>
<b class="nc">&nbsp;                clazz = loadClassFromFile();</b>
&nbsp;            }
&nbsp;
<b class="nc">&nbsp;            return (PointCalculator) clazz.newInstance();</b>
<b class="nc">&nbsp;        } catch (Exception e) {</b>
<b class="nc">&nbsp;            throw new RuntimeException(&quot;Could not dynamically load the points calculator.&quot;, e);</b>
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    private Class loadClassFromFile() throws IOException, ClassNotFoundException {
<b class="nc">&nbsp;        String strategyToLoad = getCalculatorClassName();</b>
&nbsp;
<b class="nc">&nbsp;        if (&quot;DefaultPointCalculator&quot;.equals(strategyToLoad)) {</b>
<b class="nc">&nbsp;            return DefaultPointCalculator.class;</b>
&nbsp;        }
&nbsp;
<b class="nc">&nbsp;        URL[] urls = new URL[]{getClass().getClassLoader().getResource(&quot;scoreplugins/&quot;)};</b>
&nbsp;
<b class="nc">&nbsp;        try (URLClassLoader classLoader = new URLClassLoader(urls, getClass().getClassLoader())) {</b>
<b class="nc">&nbsp;            return classLoader.loadClass(strategyToLoad);</b>
<b class="nc">&nbsp;        }</b>
&nbsp;    }
&nbsp;
&nbsp;    private String getCalculatorClassName() throws IOException {
<b class="nc">&nbsp;        Properties properties = new Properties();</b>
&nbsp;
<b class="nc">&nbsp;        properties.load(getClass().getClassLoader().getResourceAsStream(&quot;scorecalc.properties&quot;));</b>
&nbsp;
<b class="nc">&nbsp;        return properties.getProperty(&quot;scorecalculator.name&quot;);</b>
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-23 16:26</div>
</div>
</body>
</html>
